x <- seq(0,.09,length.out=10)
y.ddiNEW <- 0.06/(.5*x+0.01)
points(x,y.ddiNEW,type="l", col=colL[4], lwd=4)
legend(0.05,5,col=c(colL[3],colL[1],colL[4]),
legend = c("Signature Altman (2015)", "Signature Stutzer (1999)", "Signature Component of snDDI"),
lty = 1, lwd=4, bty="n")
dev.off()
DD.data$Index <- (DD.data$Ref + DD.data$Init + DD.data$ManRef)/3
par(family="CMU Serif", mai=c(1,1,0.5,0.5))
plot(DD.data$StutzerOHNE[1:24],DD.data$Index[1:24], type = "n", bty="n",
xlab="Stutzer Index", ylab="sub-national Direct Democracy Index (snDDI)")
text(DD.data$StutzerOHNE[1:24],DD.data$Index[1:24],
labels =  DD.data$State[DD.data$country=="CH"],
col=colL[3])
fit1 <- lm(DD.data$Index[1:24] ~ DD.data$StutzerMIT[1:24])
abline(fit1, lwd=3, col=colL[1])
CL <- round(cor(DD.data$Index[1:24],DD.data$StutzerOHNE[1:24]),2)
CL
### Call libraries
library(extrafont) # CRAN v0.17 # CRAN v0.17
library(haven)     # CRAN v2.3.1
library(xtable)    # CRAN v1.8-4
library(foreign)   # CRAN v0.8-72
library(lme4)      # CRAN v1.1-23
library(brms)      # CRAN v2.10.0
library(haven)     # CRAN v2.3.1
library(readxl)    # CRAN v1.3.1
library(arm)       # CRAN v1.10-1
library(interplot) # CRAN v0.2.2
library(sjPlot)    # CRAN v2.8.1
library(effects)   # CRAN v4.1-4
library(rstan)     # CRAN v2.19.2
library(rstanarm)  # [github::stan-dev/rstanarm] v2.19.3
library(ordinal)   # CRAN v2019.4-25
library(texreg)    # CRAN v1.36.23
library(dplyr)     # [github::tidyverse/dplyr] v0.8.99.9003
library(lmtest)    # CRAN v0.9-38
library(stargazer) # CRAN v5.2.2
library(extrafont) # CRAN v0.17
library(fontcm)    # CRAN v1.1
font_install('fontcm')
### Generate sub-nation Direct Democracy Index for all four countries
source("Code/1__DD_index_allCountries.R")
### Generate sub-nation Direct Democracy Index for all four countries
source("Code/1__DD_index_allCountries.R")
### Call libraries
library(extrafont)  # CRAN v0.17 # CRAN v0.17
library(haven)      # CRAN v2.3.1
library(xtable)     # CRAN v1.8-4
library(foreign)    # CRAN v0.8-72
library(lme4)       # CRAN v1.1-23
library(brms)       # CRAN v2.10.0
library(haven)      # CRAN v2.3.1
library(readxl)     # CRAN v1.3.1
library(arm)        # CRAN v1.10-1
library(interplot)  # CRAN v0.2.2
library(sjPlot)     # CRAN v2.8.1
library(effects)    # CRAN v4.1-4
library(ordinal)    # CRAN v2019.4-25
library(texreg)     # CRAN v1.36.23
library(plyr)       # CRAN v1.8.6
library(dplyr)      # [github::tidyverse/dplyr] v0.8.99.9003
library(lmtest)     # CRAN v0.9-38
library(stargazer)  # CRAN v5.2.2
library(extrafont)  # CRAN v0.17
library(fontcm)     # CRAN v1.1
library(tidyverse)  # CRAN v1.3.0
library(ggplot2)    # CRAN v3.3.2
library(reshape2)   # CRAN v1.4.4
library(sjlabelled) # CRAN v1.1.6
data <- read.dta("Data/Individual/2018_04_06_Aggregated_dataset_v2_stata12.dta", convert.dates = TRUE, convert.factors = TRUE,
missing.type = FALSE,
convert.underscore = FALSE, warn.missing.labels = TRUE)
#Data preparation
dataMEDW <- data%>%filter(COUNTRY == "Switzerland" | COUNTRY == "Germany")
#Democratic satisfaction national
dataMEDW$sf_national <- dataMEDW$Q1A_BEGINNING
dataMEDW$sf_national <- na_if(dataMEDW$sf_national, 99)
#Democratic satisfaction regional
dataMEDW$sf_regional <- dataMEDW$Q1B_BEGINNING
dataMEDW$sf_regional <- na_if(dataMEDW$sf_regional, 99)
satis<- dataMEDW%>% select(sf_regional,sf_national,REGIONID)
satis <- na.omit(satis)
#Correlations
func <- function(satis)
{
return(data.frame(COR = cor(satis$sf_national, satis$sf_regional)))
}
corr <- ddply(satis, .(REGIONID), func)
#Figure A4, upper graph
corrPlotMEDW <- ggplot(corr, aes(x = REGIONID, y=COR)) + geom_point(shape = 3, size = 5) + ylim(0,1) +
xlab("Subnational units") + ylab("Correlation coefficient R") + ggtitle("Data: Making Electoral Democracy Work")
corrPlotMEDW
dataREG <- dataMEDW%>%select(sf_national, sf_regional,GEND, YOB, REGIONID, Q7, Q18, Q46B, Q47_1, SD2A, POSTSECONDARY, PSD3, COUNTRY)
# age
dataREG$age <- 2017-dataREG$YOB
dataREG$age[dataREG$age<0] <- NA
dataREG$age[dataREG$age>100] <- NA
# female
dataREG$female <- "male"
dataREG$female[dataREG$GEND=="Female"] <- "female"
# education
dataREG$edu<- "low edu"
dataREG$edu[dataREG$POSTSECONDARY=="Yes"]<- "postsec. edu"
table(dataREG$edu)
# employed? (full time) => not available
# participation (High values, low participation probability)
dataREG$participation <- as.numeric(dataREG$Q7)
dataREG$participation[dataREG$Q7=="Don't know"] <- NA
table(dataREG$participation)
dataREG$participation<- as.numeric(dataREG$participation)
dataREG <- dataREG%>%select(sf_national, sf_regional,COUNTRY, participation, edu, female, age, REGIONID, Q47_1)
dataREG <- na.omit(dataREG)
# read-in data on subnational parties
DE.parties <- read_excel("Data/Subnationale Exekutiven.xlsx", sheet="DE2")
CH.parties <- read_excel("Data/Subnationale Exekutiven.xlsx", sheet="CH")
dataREG$ID <- NA
dataREG$ID[dataREG$REGIONID=="Bavaria"] <- 8
dataREG$ID[dataREG$REGIONID=="Lower Saxony"] <- 16
dataREG$ID[dataREG$REGIONID=="Lucerne"] <- 3
dataREG$ID[dataREG$REGIONID=="Zurich"] <- 1
# Parties Germany
# parties -- 1: SPD	2:CDU	(CSU)	4:Greens	5:Linke	6:FDP
dataREG$partiesDE <- 0
dataREG$partiesDE[dataREG$Q47_1=="Party 2"& dataREG$COUNTRY=="Germany"] <- 1
dataREG$partiesDE[dataREG$Q47_1=="Party 1"& dataREG$COUNTRY=="Germany"] <- 2
dataREG$partiesDE[dataREG$Q47_1=="Party 3"& dataREG$COUNTRY=="Germany"] <- 4
dataREG$partiesDE[dataREG$Q47_1=="Party 6"& dataREG$COUNTRY=="Germany"] <- 5
dataREG$partiesDE[dataREG$Q47_1=="Party 5"& dataREG$COUNTRY=="Germany"] <- 6
dataREG$winnerDE <- 0
www <- as.numeric(names(table(dataREG$ID)))
for (i in 1:length(dataREG$winnerDE)){
cr <- dataREG$ID[i]
pp <- as.numeric(DE.parties[as.numeric(as.character(cr)),])[-c(1:2)]
parties.in.power <- which(pp==1)
if (dataREG$partiesDE[i] %in% parties.in.power) dataREG$winnerDE[i] <- 1
}
#Parties Switzerland
# parties -- 1:FDP	2:CVP	3:SP	4:SVP	5:LP	6:CSP	7:BDP	8:GP	9:Lega	10: MCG	Übrige
dataREG$partiesCH
dataREG$partiesCH[dataREG$Q47_1=="Party 1"& dataREG$COUNTRY=="Switzerland"] <- 2
dataREG$partiesCH[dataREG$Q47_1=="Party 2"& dataREG$COUNTRY=="Switzerland"] <- 1
dataREG$partiesCH[dataREG$Q47_1=="Party 3"& dataREG$COUNTRY=="Switzerland"] <- 4
dataREG$partiesCH[dataREG$Q47_1=="Party 4"& dataREG$COUNTRY=="Switzerland"] <- 3
dataREG$partiesCH[dataREG$Q47_1=="Party 5"& dataREG$COUNTRY=="Switzerland"] <- 8
dataREG$partiesCH[dataREG$Q47_1=="Party 6"& dataREG$COUNTRY=="Switzerland"] <- 7
table(dataREG$partiesCH)
dataREG$winnerCH <- rep(0,dim(dataREG)[1])
for (i in 1:length(dataREG$winnerCH)){
cr <- dataREG$ID[i]
pp <- as.numeric(CH.parties[as.numeric(as.character(cr)),])[-c(1:2)]
parties.in.power <- which(pp==1)
if (dataREG$partiesCH[i] %in% parties.in.power) dataREG$winnerCH[i] <- 1
}
dataREG$winner <- dataREG$winnerCH + dataREG$winnerDE
table(dataREG$winner)
table(dataREG$winner, dataREG$COUNTRY)
#Regression as shown in Table 7 (left part, MEDW)
m1 <- lm(sf_national ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
m2 <- lm(sf_regional ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
library(stargazer)
stargazer(m1, m2,
type = 'text')
screenreg(list(m1,m2))
m1 <- lm(sf_national ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
m2 <- lm(sf_regional ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
summary(m1)
summary(m2)
screenreg(list(m1,m2))
dataREG$REGIONID
table(dataREG$REGIONID)
dataREG$REGIONID[dataREG$REGIONID=="Z\xfcrich"] <- "Zurich"
m1 <- lm(sf_national ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
m2 <- lm(sf_regional ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
screenreg(list(m1,m2))
### Satisfaction with Democracy: When Government by the People brings Electoral Losers and Winners Together
# Code Lucas Leemann and Isabelle Stadelmann-Steffen
# Validation: Link between national and subnational democratic satisfaction
# First version: December 2020
# Final version: April 2021
#########################################################
# First part: Analyses based on MEDW data:
# Data: Stephenson, Laura; Blais, Andr?; Bol, Damien; Kostelka, Filip, 2017,
# "Making Electoral Democracy Work", https://doi.org/10.7910/DVN/RR0NNQ,
# Harvard Dataverse, V2
#
#############################################################################
data <- read.dta("Data/Individual/2018_04_06_Aggregated_dataset_v2_stata12.dta", convert.dates = TRUE, convert.factors = TRUE,
missing.type = FALSE,
convert.underscore = FALSE, warn.missing.labels = TRUE)
#Data preparation
dataMEDW <- data%>%filter(COUNTRY == "Switzerland" | COUNTRY == "Germany")
#Democratic satisfaction national
dataMEDW$sf_national <- dataMEDW$Q1A_BEGINNING
dataMEDW$sf_national <- na_if(dataMEDW$sf_national, 99)
#Democratic satisfaction regional
dataMEDW$sf_regional <- dataMEDW$Q1B_BEGINNING
dataMEDW$sf_regional <- na_if(dataMEDW$sf_regional, 99)
satis<- dataMEDW%>% select(sf_regional,sf_national,REGIONID)
satis <- na.omit(satis)
#Correlations
func <- function(satis)
{
return(data.frame(COR = cor(satis$sf_national, satis$sf_regional)))
}
corr <- ddply(satis, .(REGIONID), func)
#Figure A4, upper graph
corrPlotMEDW <- ggplot(corr, aes(x = REGIONID, y=COR)) + geom_point(shape = 3, size = 5) + ylim(0,1) +
xlab("Subnational units") + ylab("Correlation coefficient R") + ggtitle("Data: Making Electoral Democracy Work")
corrPlotMEDW
#Regressions: Replicating individual level models with subnational democratic satisfaction
#########################################################
#Prepare data based on "2_Combine L1 and L2 data_USnew.R"
dataREG <- dataMEDW%>%select(sf_national, sf_regional,GEND, YOB, REGIONID, Q7, Q18, Q46B, Q47_1, SD2A, POSTSECONDARY, PSD3, COUNTRY)
dataREG$REGIONID[dataREG$REGIONID=="Z\xfcrich"] <- "Zurich"
# age
dataREG$age <- 2017-dataREG$YOB
dataREG$age[dataREG$age<0] <- NA
dataREG$age[dataREG$age>100] <- NA
# female
dataREG$female <- "male"
dataREG$female[dataREG$GEND=="Female"] <- "female"
# education
dataREG$edu<- "low edu"
dataREG$edu[dataREG$POSTSECONDARY=="Yes"]<- "postsec. edu"
table(dataREG$edu)
# employed? (full time) => not available
# participation (High values, low participation probability)
dataREG$participation <- as.numeric(dataREG$Q7)
dataREG$participation[dataREG$Q7=="Don't know"] <- NA
table(dataREG$participation)
dataREG$participation<- as.numeric(dataREG$participation)
dataREG <- dataREG%>%select(sf_national, sf_regional,COUNTRY, participation, edu, female, age, REGIONID, Q47_1)
dataREG <- na.omit(dataREG)
# read-in data on subnational parties
DE.parties <- read_excel("Data/Subnationale Exekutiven.xlsx", sheet="DE2")
CH.parties <- read_excel("Data/Subnationale Exekutiven.xlsx", sheet="CH")
dataREG$ID <- NA
dataREG$ID[dataREG$REGIONID=="Bavaria"] <- 8
dataREG$ID[dataREG$REGIONID=="Lower Saxony"] <- 16
dataREG$ID[dataREG$REGIONID=="Lucerne"] <- 3
dataREG$ID[dataREG$REGIONID=="Zurich"] <- 1
# Parties Germany
# parties -- 1: SPD	2:CDU	(CSU)	4:Greens	5:Linke	6:FDP
dataREG$partiesDE <- 0
dataREG$partiesDE[dataREG$Q47_1=="Party 2"& dataREG$COUNTRY=="Germany"] <- 1
dataREG$partiesDE[dataREG$Q47_1=="Party 1"& dataREG$COUNTRY=="Germany"] <- 2
dataREG$partiesDE[dataREG$Q47_1=="Party 3"& dataREG$COUNTRY=="Germany"] <- 4
dataREG$partiesDE[dataREG$Q47_1=="Party 6"& dataREG$COUNTRY=="Germany"] <- 5
dataREG$partiesDE[dataREG$Q47_1=="Party 5"& dataREG$COUNTRY=="Germany"] <- 6
dataREG$winnerDE <- 0
www <- as.numeric(names(table(dataREG$ID)))
for (i in 1:length(dataREG$winnerDE)){
cr <- dataREG$ID[i]
pp <- as.numeric(DE.parties[as.numeric(as.character(cr)),])[-c(1:2)]
parties.in.power <- which(pp==1)
if (dataREG$partiesDE[i] %in% parties.in.power) dataREG$winnerDE[i] <- 1
}
#Parties Switzerland
# parties -- 1:FDP	2:CVP	3:SP	4:SVP	5:LP	6:CSP	7:BDP	8:GP	9:Lega	10: MCG	Übrige
dataREG$partiesCH
dataREG$partiesCH[dataREG$Q47_1=="Party 1"& dataREG$COUNTRY=="Switzerland"] <- 2
dataREG$partiesCH[dataREG$Q47_1=="Party 2"& dataREG$COUNTRY=="Switzerland"] <- 1
dataREG$partiesCH[dataREG$Q47_1=="Party 3"& dataREG$COUNTRY=="Switzerland"] <- 4
dataREG$partiesCH[dataREG$Q47_1=="Party 4"& dataREG$COUNTRY=="Switzerland"] <- 3
dataREG$partiesCH[dataREG$Q47_1=="Party 5"& dataREG$COUNTRY=="Switzerland"] <- 8
dataREG$partiesCH[dataREG$Q47_1=="Party 6"& dataREG$COUNTRY=="Switzerland"] <- 7
table(dataREG$partiesCH)
dataREG$winnerCH <- rep(0,dim(dataREG)[1])
for (i in 1:length(dataREG$winnerCH)){
cr <- dataREG$ID[i]
pp <- as.numeric(CH.parties[as.numeric(as.character(cr)),])[-c(1:2)]
parties.in.power <- which(pp==1)
if (dataREG$partiesCH[i] %in% parties.in.power) dataREG$winnerCH[i] <- 1
}
dataREG$winner <- dataREG$winnerCH + dataREG$winnerDE
table(dataREG$winner)
table(dataREG$winner, dataREG$COUNTRY)
#Regression as shown in Table 7 (left part, MEDW)
m1 <- lm(sf_national ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
m2 <- lm(sf_regional ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
screenreg(list(m1,m2))
### Master file (executes all code)
# "Satisfaction with Democracy: When Government by the People brings Electoral Losers and Winners Together"
# Code Lucas Leemann and Isabelle Stadelmann-Steffen
# First version: April 2021
# Final version: April 2021
### Call libraries
library(extrafont)  # CRAN v0.17 # CRAN v0.17
library(haven)      # CRAN v2.3.1
library(xtable)     # CRAN v1.8-4
library(foreign)    # CRAN v0.8-72
library(lme4)       # CRAN v1.1-23
library(brms)       # CRAN v2.10.0
library(haven)      # CRAN v2.3.1
library(readxl)     # CRAN v1.3.1
library(arm)        # CRAN v1.10-1
library(interplot)  # CRAN v0.2.2
library(sjPlot)     # CRAN v2.8.1
library(effects)    # CRAN v4.1-4
library(ordinal)    # CRAN v2019.4-25
library(texreg)     # CRAN v1.36.23
library(plyr)       # CRAN v1.8.6
library(dplyr)      # [github::tidyverse/dplyr] v0.8.99.9003
library(lmtest)     # CRAN v0.9-38
library(stargazer)  # CRAN v5.2.2
library(extrafont)  # CRAN v0.17
library(fontcm)     # CRAN v1.1
library(tidyverse)  # CRAN v1.3.0
library(ggplot2)    # CRAN v3.3.2
library(reshape2)   # CRAN v1.4.4
library(sjlabelled) # CRAN v1.1.6
# age
dataREG$age <- 2017-dataREG$YOB
dataREG$age[dataREG$age<0] <- NA
dataREG$age[dataREG$age>100] <- NA
# female
dataREG$female <- "male"
dataREG$female[dataREG$GEND=="Female"] <- "female"
# education
dataREG$edu<- "low edu"
dataREG$edu[dataREG$POSTSECONDARY=="Yes"]<- "postsec. edu"
table(dataREG$edu)
# employed? (full time) => not available
# participation (High values, low participation probability)
dataREG$participation <- as.numeric(dataREG$Q7)
dataREG$participation[dataREG$Q7=="Don't know"] <- NA
table(dataREG$participation)
dataREG$participation<- as.numeric(dataREG$participation)
dataREG <- dataREG%>%select(sf_national, sf_regional,COUNTRY, participation, edu, female, age, REGIONID, Q47_1)
dataREG <- na.omit(dataREG)
# read-in data on subnational parties
DE.parties <- read_excel("Data/Subnationale Exekutiven.xlsx", sheet="DE2")
CH.parties <- read_excel("Data/Subnationale Exekutiven.xlsx", sheet="CH")
dataREG$ID <- NA
dataREG$ID[dataREG$REGIONID=="Bavaria"] <- 8
dataREG$ID[dataREG$REGIONID=="Lower Saxony"] <- 16
dataREG$ID[dataREG$REGIONID=="Lucerne"] <- 3
dataREG$ID[dataREG$REGIONID=="Zurich"] <- 1
# Parties Germany
# parties -- 1: SPD	2:CDU	(CSU)	4:Greens	5:Linke	6:FDP
dataREG$partiesDE <- 0
dataREG$partiesDE[dataREG$Q47_1=="Party 2"& dataREG$COUNTRY=="Germany"] <- 1
dataREG$partiesDE[dataREG$Q47_1=="Party 1"& dataREG$COUNTRY=="Germany"] <- 2
dataREG$partiesDE[dataREG$Q47_1=="Party 3"& dataREG$COUNTRY=="Germany"] <- 4
dataREG$partiesDE[dataREG$Q47_1=="Party 6"& dataREG$COUNTRY=="Germany"] <- 5
dataREG$partiesDE[dataREG$Q47_1=="Party 5"& dataREG$COUNTRY=="Germany"] <- 6
dataREG$winnerDE <- 0
www <- as.numeric(names(table(dataREG$ID)))
for (i in 1:length(dataREG$winnerDE)){
cr <- dataREG$ID[i]
pp <- as.numeric(DE.parties[as.numeric(as.character(cr)),])[-c(1:2)]
parties.in.power <- which(pp==1)
if (dataREG$partiesDE[i] %in% parties.in.power) dataREG$winnerDE[i] <- 1
}
#Parties Switzerland
# parties -- 1:FDP	2:CVP	3:SP	4:SVP	5:LP	6:CSP	7:BDP	8:GP	9:Lega	10: MCG	Übrige
dataREG$partiesCH
dataREG$partiesCH[dataREG$Q47_1=="Party 1"& dataREG$COUNTRY=="Switzerland"] <- 2
dataREG$partiesCH[dataREG$Q47_1=="Party 2"& dataREG$COUNTRY=="Switzerland"] <- 1
dataREG$partiesCH[dataREG$Q47_1=="Party 3"& dataREG$COUNTRY=="Switzerland"] <- 4
dataREG$partiesCH[dataREG$Q47_1=="Party 4"& dataREG$COUNTRY=="Switzerland"] <- 3
dataREG$partiesCH[dataREG$Q47_1=="Party 5"& dataREG$COUNTRY=="Switzerland"] <- 8
dataREG$partiesCH[dataREG$Q47_1=="Party 6"& dataREG$COUNTRY=="Switzerland"] <- 7
table(dataREG$partiesCH)
dataREG$winnerCH <- rep(0,dim(dataREG)[1])
for (i in 1:length(dataREG$winnerCH)){
cr <- dataREG$ID[i]
pp <- as.numeric(CH.parties[as.numeric(as.character(cr)),])[-c(1:2)]
parties.in.power <- which(pp==1)
if (dataREG$partiesCH[i] %in% parties.in.power) dataREG$winnerCH[i] <- 1
}
dataREG$winner <- dataREG$winnerCH + dataREG$winnerDE
table(dataREG$winner)
table(dataREG$winner, dataREG$COUNTRY)
#Regression as shown in Table 7 (left part, MEDW)
m1 <- lm(sf_national ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
m2 <- lm(sf_regional ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
data <- read.dta("Data/Individual/2018_04_06_Aggregated_dataset_v2_stata12.dta", convert.dates = TRUE, convert.factors = TRUE,
missing.type = FALSE,
convert.underscore = FALSE, warn.missing.labels = TRUE)
#Data preparation
dataMEDW <- data%>%filter(COUNTRY == "Switzerland" | COUNTRY == "Germany")
#Democratic satisfaction national
dataMEDW$sf_national <- dataMEDW$Q1A_BEGINNING
dataMEDW$sf_national <- na_if(dataMEDW$sf_national, 99)
#Democratic satisfaction regional
dataMEDW$sf_regional <- dataMEDW$Q1B_BEGINNING
dataMEDW$sf_regional <- na_if(dataMEDW$sf_regional, 99)
satis<- dataMEDW%>% select(sf_regional,sf_national,REGIONID)
satis <- na.omit(satis)
#Correlations
func <- function(satis)
{
return(data.frame(COR = cor(satis$sf_national, satis$sf_regional)))
}
corr <- ddply(satis, .(REGIONID), func)
#Figure A4, upper graph
corrPlotMEDW <- ggplot(corr, aes(x = REGIONID, y=COR)) + geom_point(shape = 3, size = 5) + ylim(0,1) +
xlab("Subnational units") + ylab("Correlation coefficient R") + ggtitle("Data: Making Electoral Democracy Work")
corrPlotMEDW
#Regressions: Replicating individual level models with subnational democratic satisfaction
#########################################################
#Prepare data based on "2_Combine L1 and L2 data_USnew.R"
dataREG <- dataMEDW%>%select(sf_national, sf_regional,GEND, YOB, REGIONID, Q7, Q18, Q46B, Q47_1, SD2A, POSTSECONDARY, PSD3, COUNTRY)
dataREG$REGIONID[dataREG$REGIONID=="Z\xfcrich"] <- "Zurich"
# age
dataREG$age <- 2017-dataREG$YOB
dataREG$age[dataREG$age<0] <- NA
dataREG$age[dataREG$age>100] <- NA
# female
dataREG$female <- "male"
dataREG$female[dataREG$GEND=="Female"] <- "female"
# education
dataREG$edu<- "low edu"
dataREG$edu[dataREG$POSTSECONDARY=="Yes"]<- "postsec. edu"
table(dataREG$edu)
# employed? (full time) => not available
# participation (High values, low participation probability)
dataREG$participation <- as.numeric(dataREG$Q7)
dataREG$participation[dataREG$Q7=="Don't know"] <- NA
table(dataREG$participation)
dataREG$participation<- as.numeric(dataREG$participation)
dataREG <- dataREG%>%select(sf_national, sf_regional,COUNTRY, participation, edu, female, age, REGIONID, Q47_1)
dataREG <- na.omit(dataREG)
# read-in data on subnational parties
DE.parties <- read_excel("Data/Subnationale Exekutiven.xlsx", sheet="DE2")
CH.parties <- read_excel("Data/Subnationale Exekutiven.xlsx", sheet="CH")
dataREG$ID <- NA
dataREG$ID[dataREG$REGIONID=="Bavaria"] <- 8
dataREG$ID[dataREG$REGIONID=="Lower Saxony"] <- 16
dataREG$ID[dataREG$REGIONID=="Lucerne"] <- 3
dataREG$ID[dataREG$REGIONID=="Zurich"] <- 1
# Parties Germany
# parties -- 1: SPD	2:CDU	(CSU)	4:Greens	5:Linke	6:FDP
dataREG$partiesDE <- 0
dataREG$partiesDE[dataREG$Q47_1=="Party 2"& dataREG$COUNTRY=="Germany"] <- 1
dataREG$partiesDE[dataREG$Q47_1=="Party 1"& dataREG$COUNTRY=="Germany"] <- 2
dataREG$partiesDE[dataREG$Q47_1=="Party 3"& dataREG$COUNTRY=="Germany"] <- 4
dataREG$partiesDE[dataREG$Q47_1=="Party 6"& dataREG$COUNTRY=="Germany"] <- 5
dataREG$partiesDE[dataREG$Q47_1=="Party 5"& dataREG$COUNTRY=="Germany"] <- 6
dataREG$winnerDE <- 0
www <- as.numeric(names(table(dataREG$ID)))
for (i in 1:length(dataREG$winnerDE)){
cr <- dataREG$ID[i]
pp <- as.numeric(DE.parties[as.numeric(as.character(cr)),])[-c(1:2)]
parties.in.power <- which(pp==1)
if (dataREG$partiesDE[i] %in% parties.in.power) dataREG$winnerDE[i] <- 1
}
#Parties Switzerland
# parties -- 1:FDP	2:CVP	3:SP	4:SVP	5:LP	6:CSP	7:BDP	8:GP	9:Lega	10: MCG	Übrige
dataREG$partiesCH
dataREG$partiesCH[dataREG$Q47_1=="Party 1"& dataREG$COUNTRY=="Switzerland"] <- 2
dataREG$partiesCH[dataREG$Q47_1=="Party 2"& dataREG$COUNTRY=="Switzerland"] <- 1
dataREG$partiesCH[dataREG$Q47_1=="Party 3"& dataREG$COUNTRY=="Switzerland"] <- 4
dataREG$partiesCH[dataREG$Q47_1=="Party 4"& dataREG$COUNTRY=="Switzerland"] <- 3
dataREG$partiesCH[dataREG$Q47_1=="Party 5"& dataREG$COUNTRY=="Switzerland"] <- 8
dataREG$partiesCH[dataREG$Q47_1=="Party 6"& dataREG$COUNTRY=="Switzerland"] <- 7
table(dataREG$partiesCH)
dataREG$winnerCH <- rep(0,dim(dataREG)[1])
for (i in 1:length(dataREG$winnerCH)){
cr <- dataREG$ID[i]
pp <- as.numeric(CH.parties[as.numeric(as.character(cr)),])[-c(1:2)]
parties.in.power <- which(pp==1)
if (dataREG$partiesCH[i] %in% parties.in.power) dataREG$winnerCH[i] <- 1
}
dataREG$winner <- dataREG$winnerCH + dataREG$winnerDE
table(dataREG$winner)
table(dataREG$winner, dataREG$COUNTRY)
#Regression as shown in Table 7 (left part, MEDW)
m1 <- lm(sf_national ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
m2 <- lm(sf_regional ~ winner + age + age*age + female + edu + participation + as.factor(REGIONID), data=dataREG)
screenreg(list(m1,m2))
### Master file (executes all code)
# "Satisfaction with Democracy: When Government by the People brings Electoral Losers and Winners Together"
# Code Lucas Leemann and Isabelle Stadelmann-Steffen
# First version: April 2021
# Final version: April 2021
### Call libraries
library(extrafont)  # CRAN v0.17 # CRAN v0.17
library(haven)      # CRAN v2.3.1
library(xtable)     # CRAN v1.8-4
library(foreign)    # CRAN v0.8-72
library(lme4)       # CRAN v1.1-23
library(brms)       # CRAN v2.10.0
library(haven)      # CRAN v2.3.1
library(readxl)     # CRAN v1.3.1
library(arm)        # CRAN v1.10-1
library(interplot)  # CRAN v0.2.2
library(sjPlot)     # CRAN v2.8.1
library(effects)    # CRAN v4.1-4
library(ordinal)    # CRAN v2019.4-25
library(texreg)     # CRAN v1.36.23
library(plyr)       # CRAN v1.8.6
library(dplyr)      # [github::tidyverse/dplyr] v0.8.99.9003
library(lmtest)     # CRAN v0.9-38
library(stargazer)  # CRAN v5.2.2
library(extrafont)  # CRAN v0.17
library(fontcm)     # CRAN v1.1
library(tidyverse)  # CRAN v1.3.0
library(ggplot2)    # CRAN v3.3.2
library(reshape2)   # CRAN v1.4.4
library(sjlabelled) # CRAN v1.1.6
# if you want to enable CM fonts
font_install('fontcm')
### Generate sub-nation Direct Democracy Index for all four countries
source("Code/1__DD_index_allCountries.R")
Init.US.2016 <- DD.index(x = USdata.init1, inst=1,year=2016,polity.names=USdata.init[,1])
DD.index(x = USdata.init1, inst=1,year=2016,polity.names=USdata.init[,1])
USdata.init1
USdata.init1[,6]
as.numeric(USdata.init1[,6])
